﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DCT.CodeBox.LightLog.Codes.Formatter
{
    public class DictionaryFormatter : KeyValueLogStringFormatter, ILogStringFormatter
    {
        public string Render(object log)
        {
            IDictionary<string, object> diclog = log as IDictionary<string, object>;
            if (diclog == null) {
                return null;
            }

            List<string> logs = new List<string>();
            foreach (var item in diclog)
            {
                logs.Add(string.Format(this.Formatter, item.Key, item.Value.ToString()));
            }
            return string.Join(this.Split, logs.ToArray());
        }
    }
}
